home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / Hydra11s.lha / HBBS / Source / Misc / TecLisMailSys / MailEdit.c < prev    next >
C/C++ Source or Header  |  1996-06-25  |  8KB  |  280 lines

  1. /*
  2.    changed list
  3.  
  4.   made it so that user can enter blank line on the To: prompt to cancel the message..
  5.  
  6.   SYSOP is valid in the TO: string..
  7.  
  8. */
  9.  
  10. #include <stdio.h>
  11. #include <stdlib.h>
  12. #include <string.h>
  13.  
  14. #include <dos/dos.h>
  15. #include <exec/types.h>
  16. #include <exec/memory.h>
  17.  
  18. #include <clib/dos_protos.h>
  19. #include <clib/exec_protos.h>
  20. #include <clib/alib_protos.h>
  21.  
  22. #include <HBBS/ANSI_Codes.h>
  23. #include <HBBS/Defines.h>
  24. #include <HBBS/types.h>
  25. #include <HBBS/structures.h>
  26. #include <HBBS/hbbscommon_protos.h>
  27. #include <HBBS/hbbscommon_pragmas.h>
  28. #include <HBBS/Hbbsnode_protos.h>
  29. #include <HBBS/Hbbsnode_pragmas.h>
  30.  
  31. #include "maildoor.h"
  32. #include "mailscan.h"
  33. #include "mailread.h"
  34. #include "mailedit.h"
  35.  
  36. char UserNames[MAX_PATH_LENGTH];
  37. char UserIDs[MAX_PATH_LENGTH];
  38.  
  39. int MAILEDIT_CheckValidUser( char *UserName )
  40. {
  41.   int ValidsFound = 0, r=0;
  42.   char str[BUFFER_LENGTH], temp[BUFFER_LENGTH],*copyofname, outstr[BUFFER_LENGTH];
  43.   struct UserData UserDat;
  44.   BOOL Done=FALSE;
  45.   short where;
  46.  
  47.   if (copyofname=DupStr(UserName))
  48.   {
  49.     do
  50.     {
  51.       str[0]=0;
  52.       if ((where=position(",",copyofname))>=0)
  53.       {
  54.         strNcpy(str,copyofname,where);
  55.         strfcpy(copyofname,copyofname,where+1);
  56.       }
  57.       else
  58.       {
  59.         Done=TRUE;
  60.         strcpy(str,copyofname);
  61.       }
  62.       if (str[0])
  63.       {
  64.         if (stricmp("SYSOP",str)==0)  // replace SYSOP string with sysop's name..
  65.         {
  66.           strcpy(str,BBSGlobal->SysopAccount);
  67.         }
  68.  
  69.  
  70.         if( HBBS_ValidUserHandle( str, &UserDat ) )
  71.         {
  72.           ValidsFound++;
  73.           sprintf( temp, "%d", UserDat.UserID );
  74.           if( ValidsFound > 1 )
  75.           {
  76.             strcat( UserIDs, "," );
  77.             strcat( UserNames, "," );
  78.           }
  79.           strcat( UserIDs, temp );
  80.           strcat( UserNames, str );
  81.         }
  82.         else
  83.         {
  84.           sprintf( outstr, ANSI_FG_RED" ERROR : "ANSI_FG_PURPLE"%s is an invalid name!\r\n\r\n"ANSI_FG_YELLOW"Enter name to replace %s with "ANSI_FG_WHITE":", str, str );
  85.           DOOR_WriteText( outstr );
  86.           DOOR_GetLine( TRUE, TRUE, 0 );
  87.           if( N_ND->OnlineStatus==OS_ONLINE )
  88.           {
  89.             if( N_ND->CurrentLine[0] )
  90.             {
  91.               if( ValidsFound >= 1 )
  92.               {
  93.                 strcat( UserIDs, "," );
  94.                 strcat( UserNames, "," );
  95.               }
  96.               r = MAILEDIT_CheckValidUser( N_ND->CurrentLine );
  97.               if( r == 0 )
  98.               {
  99.                 if( ValidsFound > 1)
  100.                 {
  101.                   UserIDs[strlen(UserIDs)-1]=0;
  102.                   UserNames[strlen(UserNames)-1]=0;
  103.                 }
  104.               }
  105.               else
  106.                 ValidsFound += r;
  107.             }
  108.           }
  109.         }
  110.       }
  111.       else
  112.       {
  113.         Done=TRUE;
  114.       }
  115.  
  116.     } while (!Done);
  117.  
  118.     FreeStr(copyofname);
  119.   }
  120.   return( ValidsFound );
  121. }
  122.  
  123. BOOL MAILEDIT_LineEditor( char *filename )
  124. {
  125.   char outstr[BUFFER_LENGTH];
  126.   BOOL Done = FALSE;
  127.   BPTR file;
  128.   int n, N=0;
  129.  
  130.   if( file = Open( filename, MODE_NEWFILE ))
  131.   {
  132.     DOOR_WriteText( "\r\n    /----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----"ANSI_FG_GREEN"*"ANSI_FG_WHITE"----/\r\n\r\n" );
  133.     n=0;
  134.     while( !Done )
  135.     {
  136.       n++;
  137.       sprintf( outstr, "%03d ", n );
  138.       DOOR_WriteText( outstr );
  139.       DOOR_GetLine( TRUE, TRUE, 0 );
  140.       if( N_ND->OnlineStatus==OS_ONLINE )
  141.       {
  142.         if( N_ND->CurrentLine[0] )
  143.         {
  144.           sprintf( outstr, "%s\n", N_ND->CurrentLine );
  145.           FPuts( file, outstr );
  146.           N=0;
  147.         }
  148.         else
  149.         {
  150.           N++;
  151.           if( N==2 ) Done = TRUE;
  152.         }
  153.       }
  154.       else Done = TRUE;
  155.     }
  156.     Close( file );
  157.   }
  158.   return( TRUE );
  159. }
  160.  
  161. BOOL MAILEDIT_SaveMessageData( struct MAIL_Message *MM, int ConfNum, int MsgNum )
  162. {
  163.   char outstr[BUFFER_LENGTH], filename[MAX_PATH_LENGTH];
  164.   struct Node *ConfPtr;
  165.   struct CfgFileData *CfgFile;
  166.  
  167.   ConfPtr = GetNode( BBSGlobal->ConfList, ConfNum-1 );
  168.  
  169.   sprintf( filename, "%sMail/Messages/%d.DAT\0", ((struct ConfData *)ConfPtr)->ConfPath, MsgNum );
  170.  
  171.   if( CfgFile = HBBS_CreateConfig( filename) )
  172.   {
  173.     if( HBBS_AddCfgItem( CfgFile, "From", MM->MM_From ))
  174.     {
  175.       if( HBBS_AddCfgItem( CfgFile, "For", MM->MM_For ))
  176.         if( HBBS_AddCfgItem( CfgFile, "ForIDs", MM->MM_ForIDs ))
  177.           if( HBBS_AddCfgItem( CfgFile, "Subject", MM->MM_Subject ))
  178.           {
  179.             sprintf( outstr, "%d", MM->MM_Read );
  180.             if( HBBS_AddCfgItem( CfgFile, "Read", outstr ))
  181.             {
  182.               sprintf( outstr, "%d", MM->MM_DownLoaded );
  183.               if( HBBS_AddCfgItem( CfgFile, "Downloaded", outstr ))
  184.               {
  185.                 sprintf( outstr, "%d", MM->MM_FilesDL );
  186.                 if( HBBS_AddCfgItem( CfgFile, "FilesDL", outstr ))
  187.                 {
  188.                   sprintf( outstr, "%d", MM->MM_NAttachedFiles );
  189.                   HBBS_AddCfgItem( CfgFile, "NAttached", outstr );
  190.                 }
  191.               }
  192.             }
  193.           }
  194.  
  195.       HBBS_SaveConfig( CfgFile );
  196.     }
  197.     HBBS_FlushConfig( CfgFile );
  198.   }
  199.   else return( FALSE );
  200.   return( TRUE );
  201. }
  202.  
  203. void MYDOOR_DoEnterMessage( char *ToName )
  204. {
  205.   char outstr[BUFFER_LENGTH],filename[MAX_PATH_LENGTH], NAME[BUFFER_LENGTH];
  206.   struct MAIL_Message *NewMessage;
  207.   int ConfNum, MsgNum, FirstMessage, LastMessage;
  208.   struct Node *ConfPtr;
  209.  
  210.   ConfNum = N_ND->CurrentConf->ConfNum;
  211.   ConfPtr = GetNode( BBSGlobal->ConfList, ConfNum-1 );
  212.  
  213.   FirstMessage = MAILSCAN_GetFirstMessage( ConfNum );
  214.   LastMessage = MAILSCAN_GetLastMessage( ConfNum );
  215.  
  216.   MsgNum = LastMessage + 1;
  217.  
  218.   if( NewMessage = AllocVec( sizeof( struct MAIL_Message ), MEMF_CLEAR|MEMF_PUBLIC ))
  219.   {
  220.     strcpy( NewMessage->MM_From, N_ND->User.CallData.Handle );
  221.     NewMessage->MM_Read = 0;
  222.     NewMessage->MM_DownLoaded = 0;
  223.     NewMessage->MM_FilesDL = 0;
  224.     NewMessage->MM_NAttachedFiles = 0;
  225.  
  226.     UserIDs[0] = 0;
  227.     UserNames[0] = 0;
  228.     do
  229.     {
  230.       DOOR_WriteText(ANSI_FG_YELLOW "To      "ANSI_FG_WHITE":" );
  231.       if( ToName == NULL )
  232.       {
  233.         DOOR_GetLine( TRUE, TRUE, 0 );
  234.         strcpy( NAME, N_ND->CurrentLine );
  235.       }
  236.       else
  237.       {
  238.         DOOR_WriteText( "SYSOP\r\n" );
  239.         strcpy( NAME, ToName );
  240.       }
  241.     }while((N_ND->CurrentLine[0]) && (!(MAILEDIT_CheckValidUser( NAME )))&&(N_ND->OnlineStatus==OS_ONLINE));
  242.     if(N_ND->OnlineStatus==OS_ONLINE)
  243.     {
  244.       if (N_ND->CurrentLine[0]==0)
  245.       {
  246.         DOOR_WriteText("Message Cancelled\n\r");
  247.       }
  248.       else
  249.       {
  250.         strcpy( NewMessage->MM_ForIDs, UserIDs );
  251.         strcpy( NewMessage->MM_For, UserNames );
  252.         DOOR_WriteText(ANSI_FG_YELLOW "Subject "ANSI_FG_WHITE":" );
  253.         DOOR_GetLine( TRUE, TRUE, 0 );
  254.         strcpy( NewMessage->MM_Subject, N_ND->CurrentLine );
  255.         if( N_ND->OnlineStatus==OS_ONLINE )
  256.         {
  257.           sprintf( filename, "%sMail/Messages/%d.TXT\0", ((struct ConfData *)ConfPtr)->ConfPath, MsgNum );
  258.           if( MAILEDIT_LineEditor( filename ))
  259.           {
  260.             strcpy( NewMessage->MM_ForIDs, UserIDs );
  261.             if( !(MAILEDIT_SaveMessageData( NewMessage, ConfNum, MsgNum )))
  262.             {
  263.               DOOR_WriteText( ANSI_FG_RED"Problems Saving Message\r\n"ANSI_FG_WHITE );
  264.             }
  265.             else
  266.             {
  267.               sprintf( outstr, "%d", MsgNum );
  268.               if( (FirstMessage == 0 ) && (LastMessage == 0 ) )
  269.                 MAILREAD_UpdateConfMailData( ConfNum, FirstMessage, LastMessage, outstr, MailSys_Both );
  270.               else
  271.                 MAILREAD_UpdateConfMailData( ConfNum, FirstMessage, LastMessage, outstr, MailSys_OFFSET_LastMessage );
  272.               DOOR_WriteText( ANSI_FG_GREEN"Message Saved!\r\n"ANSI_FG_WHITE );
  273.             }
  274.           }
  275.         }
  276.       }
  277.     }
  278.   }
  279. }
  280.